package com.zsy.controller;

import com.zsy.entity.Official;
import com.zsy.entity.Plan;
import com.zsy.entity.Research;
import com.zsy.service.IResearchService;
import com.zsy.utils.PageBean;
import com.zsy.utils.Result;
import com.zsy.utils.Result02;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Validated
//跨域问题解决方案
@CrossOrigin
public class ResearchController {

    @Autowired
    IResearchService is;//获取到研发门户的接口

   //    研发申请接口
/**
 * 添加研发申请
 * 此方法通过POST请求接收研发申请信息，并将其添加到系统中
 *
 * @param re Research对象，包含研发申请的相关信息
 * @return 返回操作结果，包括成功或失败的信息
 */
@PostMapping("/addresearch")
public Result add(Research re){
    // 打印添加研发申请的信息，用于调试和日志记录
    System.out.println("添加研发申请"+re.toString());
    // 调用insertResearch方法将研发申请信息插入数据库，并返回操作结果
    return is.insertResearch(re);

}

    //查数据与数据条数,分页
    @GetMapping("/requestFormInquiry")
    public Result select(Research research){
        return is.selectResearch(research);
    }
    @GetMapping("/selectRes")
    public Result selectRes(Research research) {
        return is.selectRes(research);
    }

    @GetMapping("/list")
    public Result02<PageBean<Research>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer estimatedHeadcount,
            @RequestParam(required = false) String rdCity,
            @RequestParam(required = false) String rdType) {
        System.out.println("Controller:"+estimatedHeadcount + " " + rdCity + " " + rdType);
        PageBean<Research> list = is.list(pageNum, pageSize, estimatedHeadcount, rdCity, rdType);
        return Result02.success(list);
    }

    //删除研发申请表
    @PostMapping("/deleteres")
    public Result delete(Integer[] researchId){
        return is.deleteResearch(researchId);
    }

//    修改研发申请表
    @PostMapping("/updateres")
    public Result update(Research research){
        return is.updateResearch(research);
    }

        //添加计划
    @PostMapping("/addplan")
    public Result addPlan(Plan plan){
        return is.insertPlan(plan);
    }
    //查询计划
    @GetMapping("/selectPlan")
    public Result selectPlan(Plan plan){
        return is.selectPlan(plan);
    }
//    删除
    @PostMapping("/delPlan")
    public Result delPlan(Integer[] planId){
        return is.deletePlan(planId);
    }
//    修改
    @PostMapping("/updateplan")
    public Result updateplan(Plan plan){
        return is.updatePlan(plan);
    }


    //    文案
//    添加文案
    @PostMapping("/addcontent")
    public Result addOffice(Official official){
        return is.addOffice(official);
    }
//    查看文案
    @GetMapping("/selectOfficial")
    public Result selectOfficial(Official official){
        return is.selectOfficial(official);
    }
    @PostMapping("/delOfficial")
    public Result delOfficial(Integer[] officialId){
        return is.delofficlal(officialId);
    }

}
